#ifndef clox_memory_h
#define clox_memory_h

#include "common.h"
#include "value.h"

#define GROW_CAPACITY(capacity) \
    ((capacity) < 8 ? 8 : (capacity * 2))

#define GROW_ARRAY(type, ptr, oldCount, newCount) \
    (type *)(reallocate(ptr, sizeof(type) * (oldCount), sizeof(type) * (newCount)))

#define FREE_ARRAY(type, ptr, oldCount) \
    reallocate(ptr, sizeof(type) * (oldCount), 0)

#define FREE(type, pointer) reallocate(pointer, sizeof(type), 0)

#define ALLOCATE(type, count)\
    (type *)reallocate(NULL, 0, sizeof(type) * (count))

void* reallocate(void *pointer, size_t oldSize, size_t newSize);
void markValue(Value value);
void markObject(Obj* object);
void collectGarbage();
void freeObjects();
#endif